﻿using System.Collections.Generic;
using System.Windows.Forms;

namespace GeoSketch2.Core
{
    /// <summary>
    /// A tool to draw a zoom box free hand, actually you just have sketch around the area you want to zoom in
    /// </summary>
    public class TZoomBox:BaseTool
    {
        #region Fields
        List<Point2D64D> Points;
        bool _MouseDown; 
        #endregion

        #region Constructor
        /// <summary>
        /// A tool to draw a zoom box free hand, actually you just have sketch around the area you want to zoom in
        /// </summary>
        /// <param name="Viewport">The viewport the tool with act on</param>
        public TZoomBox(BaseViewport Viewport)
            : base(Viewport, "Zoombox")
        {
            _MouseDown = false;
        } 
        #endregion

        #region Inputs
        /// <summary>
        /// The event which happens when the mouse button is down
        /// </summary>
        /// <param name="MouseArgs">The mouse argument</param>
        public override void MouseDown(MouseEventArgs MouseArgs)
        {
            Points = new List<Point2D64D>();
            _MouseDown = true;
        }

        /// <summary>
        /// The event which happens when the mouse button is up
        /// </summary>
        /// <param name="MouseArgs">The mouse argument</param>
        public override void MouseUp(MouseEventArgs MouseArgs)
        {
            _MouseDown = false;
            Viewport.CurrentObjectView = Tools.GetRectangleDBounds(Viewport.Object2ImageTransformation.InverseTransform(Points.ToArray()), YAxisDirection.UpSide);
            RefreshViewport();
        }

        /// <summary>
        /// The event which happens when the mouse moves
        /// </summary>
        /// <param name="MouseArgs">The mouse argument</param>
        public override void MouseMove(MouseEventArgs MouseArgs)
        {
            if (_MouseDown)
            {
                Points.Add(MouseArgs.Location);
                Viewport.Graphic.DrawEllipse(Vars.Setup.Tools.TZoomBox.SketchPen, MouseArgs.X, MouseArgs.Y, 1, 1);
            }
        } 
        #endregion

        #region Methods
        /// <summary>
        /// The method to be used to send the first message to the user, just after beeing selected
        /// </summary>
        public override void SendFirstMessage()
        {
            SendMessage("Wrap the zone to zoom in");
        } 
        #endregion
    }
}
